package com.chai.controller;

import com.chai.exception.BusinessException;
import com.chai.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常的处理类
 * 发生异常后返回给前端的数据
 * 统一为json格式
 * */

/**需要在springmvc中进行扫描*/
@RestControllerAdvice
public class ProjectExceptionAdvice {
    /**处理业务处理的异常*/
    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException e){
        //记录日志
        //发送消息给运维
        return new Result(e.getCode(),null,e.getMessage());

    }
    /**处理系统异常的返回通知*/
    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException e){
        return new Result(e.getCode(),null,e.getMessage() );
    }
    /**负责处理其他异常*/
    @ExceptionHandler(Exception.class)
    public Result doException(Exception e){
        return new Result(Code.SYSTEM_UNKNOWN_ERR,null,"服务器繁忙....");
    }
}
